<% layout('layout/layout') %>
<% block('header').append(`<style>
.show_img{
    max-height:250px;
}
</style>`) %>
<div class="row">
    <div class="col-md-12">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">添加单页</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form action="<%=assetsPath %>/article/add" method="post" class="form-horizontal" novalidate>
                <div class="box-body">
                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">文章标题</label>
                        <div class="col-sm-10">
                            <input name="title" value="<%=curr.title || ''%>" type="text" class="form-control"  placeholder="单页标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">副标题</label>
                        <div class="col-sm-10">
                            <input name="subTitle" value="<%=curr.subTitle || ''%>" type="text" class="form-control"  placeholder="副标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">图片上传</label>
                        <div class="col-sm-10">
                            <a id="imgUpload" class="btn  btn-sm btn-success">图片上传</a>
                            <input id="imgInput" name="imgUrl" type="hidden" value="<%=curr.imgUrl || ''%>">
                            <div id="showImg" class="show_img" style="width:200px;" >
                                <% if (curr.imgUrl){ %>
                                <i class="ionfont "></i>
                                <img src="<%=curr.imgUrl %>" style="max-height:100%;max-width:100%" >
                                <% }%>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="catalogStr" class="col-sm-2 control-label">父菜单</label>
                        <div class="col-sm-10">
                            <select name="catalogStr" class="form-control">
                                <% catalogs.forEach(function(item){ %>
                                    <option <%=curr.catalogName === item.name? 'selected':'' %>  value="<%=item._id %>|<%=item.name%>|<%=item.calPath %>,<%=item.name %>"><%=item.nameCn %></option>
                                <% })%>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="content" class="col-sm-2 control-label">正文内容</label>
                        <div class="col-sm-10">
                            <div id="editor"><%- curr.content %></div>
                            <textarea id="content" hidden name="content"><%- curr.content %></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-3">
                            <div class="checkbox">
                                <label>
                                    <input name="isTop" <%=curr.isTop==1?'checked':''%> value="1" type="checkbox" > 置顶
                                </label>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="checkbox">
                                <label>
                                    <input name="isHot" <%=curr.isHot==1?'checked':'' %> value="1" type="checkbox"> 精选
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <div class="col-sm-offset-2 col-sm-10">
                        <% if(curr._id){ %>
                        <input name="_id" value="<%=curr._id %>" type="hidden">
                        <% } %>
                        <button type="submit" class="btn btn-info ">保存</button>
                        <button type="reset" class="btn btn-default">重置</button>
                    </div>
                </div>
                <!-- /.box-footer -->
            </form>
        </div>
    </div>
</div>
<% block('footer').append(`<script src="${assetsPath}/js/uploadImg.js"></script>`); %>
<% block('footer').append(`<script src="${assetsPath}/js/wangeditor/wangEditor.js"></script>`); %>
<% block('footer').append(`<script>
jQuery(function() {
	function createImg () {
		var img
		return function (url,cb) {
			if (!img) {
                img = new Image()
                img.src = url
                img.style['max-width'] = '100%'
                img.style['max-height'] = '100%'
                img.onload = function () {
                    img.onload = null
                    cb(img)
                }
            } else {
				img.src = url
				img.onload =function () {
					img.onload = null
					cb(img)
				}
            }
		}
	}
	var getImg =  createImg()
	$('#imgUpload').uploadImg(function(imgs){
    	if (imgs && imgs.length > 0) {
            var url = imgs[0].thumb.url
    	    $('#imgInput').val(url)
            getImg(url,function(img){
               $('#showImg').empty().append(img)
            })
    	}
    })
})
</script>`) %>